﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using BulldogCMS.Core.Storage;

namespace BulldogCMS.Core.MVC
{
    public abstract class BulldogWebViewPage<TModel> : System.Web.Mvc.WebViewPage<TModel>
    {
        private BulldogHelper _bulldog = new BulldogHelper();
        private ModuleHelper _module = new ModuleHelper();

        public BulldogHelper Bulldog
        {
            get
            {
                return this._bulldog;
            }
        }

        public Node Node
        {
            get
            {
                if (BulldogCMS.Core.Context.Request != null)
                {
                    return BulldogCMS.Core.Context.Request.CurrentNode;
                }
                return null;
            }
        }

        public Tree Tree
        {
            get
            {
                if (BulldogCMS.Core.Context.Application != null)
                {
                    return BulldogCMS.Core.Context.Application.Tree;
                }
                return null;
            }
        }

        public ModuleHelper Module
        {
            get
            {
                return this._module;
            }
        }

        public dynamic NodeBag
        {
            get
            {
                if (this.Node != null) {
                    return this.Node.Bag;
                }
                throw new ApplicationException("Context node not available");
            }
        }
    }

    public abstract class BulldogWebViewPage : WebViewPage<dynamic>
    {

    }
}